/*
 * 杭州东城驱动板控制协议
 * 
 * 报文格式为：STX FL ADDR SEQ CMD LEN INFO BCC ETX 
 * 
 */

#ifndef CDONGCHENGDCBTRANSPORT_H_
#define CDONGCHENGDCBTRANSPORT_H_

#include "ICommonDCBTransport.h"

namespace zl
{
namespace zlbase
{

class CDongchengDCBTransport : public ICommonDCBTransport
{
public:
    CDongchengDCBTransport() = default;
    ~CDongchengDCBTransport() = default;

    inline std::string Version() override { return "v1.0.0"; }

	inline int32_t OpenLocker(int32_t col, int32_t index) override
	{
		return cmd_openlocker(col, index);
	}

	inline int32_t GetDoorStatus(int32_t col, unsigned char* status, size_t& len) override
	{
		return cmd_getdoorstatus(col, status, len);
	}

	inline int32_t GetItemStatus(int32_t col, unsigned char* status, size_t& len) override
	{
		return cmd_getitemstatus(col, status, len);
	}

	inline int32_t GetFirmwareVersion(int32_t col, unsigned char* version, size_t& len) override
	{
		return cmd_getfirmwareversion(col, version, len);
	}

protected:
    static inline uint8_t generate_seq()
    {
        static uint8_t _val = 0;
        return _val++;
    }

	int32_t cmd_openlocker(int32_t col, int32_t index);
	int32_t cmd_getdoorstatus(int32_t col, unsigned char* status, size_t& len);
	int32_t cmd_getitemstatus(int32_t col, unsigned char* status, size_t& len);
	int32_t cmd_getfirmwareversion(int32_t col, unsigned char* version, size_t& len);

	void convert_status_data(const unsigned char* origin, size_t len,
		unsigned char* status, size_t& status_len);
};

} // namespace zlbase
} // namespace zl

#endif // CDONGCHENGDCBTRANSPORT_H_